/*
#    Copyright By Schips, All Rights Reserved
#    https://gitee.com/schips/
#
#    File Name:  thread_pool_demo.c
#    Created  :  Mon 09 Sep 2019 09:24:50 AM HKT
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "debug.h"

#include "thread_pool.h"
void *task1(void*arg)
{
    DEBUG_YELLOW("TASK GO\n");
    return NULL;
}

int main(int argc, char *argv[])
{

	struct task_arg taskarg;
    thread_pool *pool;
    thread_pool *pool2;

    // 允许最大20条工作线程， 并初始化10条
	pool = init_pool(20, 10);
    printf("%p, max%d, a%d\n", pool, pool->max_active_threads, pool->active_threads);
    
	pool2 = init_pool(10, 10); // 第二次初始化时参数无效
    printf("%p, max%d, a%d\n", pool2, pool2->max_active_threads, pool2->active_threads);
    if(pool == pool2)
    {
        // 在单例模式中， 确保进程中只有一个线程池（所以地址总是唯一的）
        printf("Same addr for a thread pool.\n");
    }
    
    // 重设线程池最大线程数，这个值将影响目前活跃的工作线程
    set_max_active_threads(pool, 5);

    // 添加 任务
    add_task(pool, task1, (void *)&taskarg);
    
    // 线程池的销毁
    destroy_pool(&pool);
    return 0;
}

